package cn.curtain.girl.handle;

import cn.curtain.girl.domain.Girl;
import cn.curtain.girl.domain.Result;
import cn.curtain.girl.exception.GirlException;
import cn.curtain.girl.utils.ResultUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import sun.awt.SunHints;

@ControllerAdvice
public class ExceptionHandle {

    private Logger logger = LoggerFactory.getLogger(ExceptionHandle.class);

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public Result handle(Exception e){
        if (e instanceof GirlException){
            GirlException girlException = (GirlException) e;
            return ResultUtil.fail(girlException.getCode(),girlException.getMessage());
        }
        logger.error("系统异常",e);
        return ResultUtil.fail(-1,"未知错误");
    }
}
